<?php require VIEW_PATH."/header.php";?>
<body>
	<link rel="stylesheet" type="text/css" href="Public/org/bootstrap/css/bootstrap.css">
	<div class="hd-menu-list">
		<ul>
			<li class="active"><a href="#">商品管理</a></li>
		</ul>
	</div>
	<table class="hd-table hd-table-list">
		<thead>
			<tr>
				<td class="hd-w150">货品ID</td>

				<td>组合属性ID</td>
				<td>商品货号</td>
				<td>库存数量</td>
				<td>
					操作
				</td>
			</tr>
		</thead>
		<tbody>
			{{foreach from="$data" value="$v"}}
			<tr>
				<td>{{$v['store_id']}}</td>

				<td>
					{{$v['mix_id']}}
				</td>
				<td>
					<input type="text" name="goods_num" id="" value="{{$v['goods_num']}}" onblur="edit(this)">

				</td>
				<td>
					<input type="text" name="store_num" id="" value="{{$v['store_num']}}" onblur="edit(this)">

				</td>
				<td>
					<a value="" href="javascript:del({{$v['store_id']}})">删除</a>
				</td>
			</tr>
			{{endforeach}}
		</tbody>
	</table>
	<script type="text/javascript">
		function del(obj)
		{

			if (confirm('确认删除吗?')) {
				$.post("{{U('delStore')}}", {store_id:obj}, function(data){

					hd_alert({

						message: data.message,

						timeout: 3,

					})
					// sleep(3);
					$("td:contains('"+obj+"')").parent().remove();

				},'json')
			};
		}


		function edit(obj)
		{

			var store_id = $(obj).parents('td').eq(0).siblings('td').eq(0).html();
			var name = $(obj).attr('name');
			var value =$(obj).val();
			$.post("{{U('editStore')}}", {store_id:store_id,name:name,value:value}, function(data){

				hd_alert({

	            message: data.message,//显示内容

	            timeout: 3,//显示时间

	        })

			},'json')
		}

	</script>

	<form action="" method="post" style="margin-top: 50px;">
		<div style="overflow: hidden;height:auto;">
			<h3 style="display: inline-block;margin:0 auto;">添加</h3>
		</div>
		<table class="hd-table hd-table-list">
			<thead>
				<tr>
					{{foreach from="$num" value = "$n"}}
					<td>
						{{$n[0]['attr_name']}}
					</td>
					{{endforeach}}
					<td>商品货号</td>
					<td>库存数量</td>
					<td>添加货品</td>
				</tr>
			</thead>
			<tbody>
				<tr id="tr">
					{{foreach from="$num" value = "$n"}}
					<td>
						<select name="attr[{{$n[0]['attr_id']}}][]" id="">
							{{foreach from = "$n" value = "$m"}}
							<option value="{{$m["good_attr_id"]}}">
								{{$m["attr_values"]}}
							</option>
							{{endforeach}}
						</select>
					</td>
					{{endforeach}}

					<td>
						<input type="text" name="goods_num[]" id="">
					</td>
					<td>
						<input type="text" name="store_num[]" id="">
					</td>
					<td>
						<button type="button" onclick="addtr(this)" class="hd-btn hd-btn-success" style="">
							添加货物
						</button>
					</td>
				</tr>
			</tbody>
		</table>
		<input type="submit" value="添加货品" class="hd-btn hd-btn-success" style="float:right;margin:30px 100px 0 0;">
	</form>

	<div style="height: 200px;">
	</div>
	<script type="text/javascript">
		function addtr(obj)
		{
			var nowtr = $(obj).parents('tr').eq(0);
			var tr = nowtr.clone();
			tr.find('button').html('[-]').attr('onclick','removePrice(this)').parents('td').siblings().find('input').val('');
			nowtr.after(tr);
		}
		function removePrice(obj)
		{
			$(obj).parents('tr').eq(0).remove();
		}
	</script>
	<style type="text/css">
		select{
			border: 1px solid #333;
			width:80%;
			height: 20px;
		}
		table input{
			border: 1px solid #333;
			width:40%;
			height: 20px;
			text-indent:10px;
			text-align:center;
		}
		td{
			text-align:center;
		}
	</style>
</body>
</html>